//
//  TrackStaticTableViewCell.m
//  location
//
//  Created by Dongxiang Xu on 2024/5/11.
//

#import "TrackStaticTableViewCell.h"

@interface TrackStaticTableViewCell ()

@property (nonatomic, strong) UIButton *mapImg;
@property (nonatomic, strong) UILabel *title;
@property (nonatomic, strong) UILabel *time;
@property (nonatomic, strong) UIButton *note;
@property (nonatomic, strong) NSDictionary *info;

@end

@implementation TrackStaticTableViewCell

- (void)prepareForReuse {
    [super prepareForReuse];
    // 重置或保持状态
}

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.contentView.backgroundColor = RealWhiteColor;
        
        _mapImg = [[UIButton alloc] initWithFrame:CGRectMake(16, 0, 42, 42)];
        _mapImg.layer.masksToBounds = YES;
        [_mapImg.layer setCornerRadius:8];
        _mapImg.backgroundColor = WhiteColor;
        [_mapImg setImage:[UIImage imageNamed:@"dingwei-3"] forState:UIControlStateNormal];
        [self.contentView addSubview:_mapImg];
                
        _title = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(_mapImg.frame)+12, _mapImg.y , SCREEN_WIDTH-CGRectGetMaxX(_mapImg.frame)-78, 24)];
        _title.textColor = RealBlackColor;
        _title.font = REAL_MEDIUM_FONT(16);
        [self.contentView addSubview:_title];
        
        _time = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(_mapImg.frame)+12, CGRectGetMaxY(_title.frame)+2, SCREEN_WIDTH-CGRectGetMaxX(_mapImg.frame)-78, 16)];
        _time.textColor = GraryLightColor;
        _time.font = DEFAULT_FONT(14);
        [self.contentView addSubview:_time];
        
        _note = [[UIButton alloc] initWithFrame:CGRectMake(SCREEN_WIDTH-54, 2, 38, 38)];
        _note.backgroundColor = LightBGColor;
        _note.layer.masksToBounds = YES;
        [_note.layer setCornerRadius:19];
        [_note setImage:[UIImage imageNamed:@"bling"] forState:UIControlStateNormal];
        [self.contentView addSubview:_note];
        [[_note rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
            if (self.TrackStaticRegionBlock) {
                CLLocationCoordinate2D coord = CLLocationCoordinate2DMake([[self.info[@"array"] firstObject][@"latitude"] doubleValue],[[self.info[@"array"] firstObject][@"longtitude"] doubleValue]);
                self.TrackStaticRegionBlock(coord);
            }
        }];
    }
    return self;
}

- (void)loadWithInfo:(NSDictionary *)info
{
    _info = info;
    if (info[@"region"]) {
        [_mapImg setImage:[UIImage imageNamed:info[@"region"][@"avatar"]] forState:UIControlStateNormal];
        _title.text = [NSString stringWithFormat:@"%@",info[@"region"][@"name"]];
        _note.hidden = YES;
    }else{
        [_mapImg setImage:[UIImage imageNamed:@"dingwei-3"] forState:UIControlStateNormal];
        if ([info[@"title"] isKindOfClass:[NSString class]] && [info[@"title"] length]>0) {
            _title.text = [NSString stringWithFormat:@"%@",info[@"title"]];
        }else{
            _title.text = @"";
        }
        _note.hidden = NO;
    }
   
    _time.text = [NSString stringWithFormat:@"%@",info[@"timeRun"]];
}
@end
